---
title: "Economic Self-Interest and Americans' Redistributive, Class, and Racial Attitudes: The Case of Economic Insecurity"
author: "Cody R. Melcher"
date: "`r format(Sys.time(), '%B %d, %Y')`"
header-includes:
  - \usepackage{setspace}\doublespacing
  - \usepackage{float}
  - \pagenumbering{gobble}
output: pdf_document
indent: true
number_sections: true
fontsize: 10pt
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F,size='tiny')
require(data.table)
require(car)
require(survey)
```

```{r the_code}
setwd("~/Desktop/Political Behavior RandR")


anes=fread("PB_Revise1.csv", stringsAsFactors = F,data.table = F)

anes$race=anes$V161310X
anes$race=factor(anes$race,levels = 1:7,labels=c("white","black","asian","native","hispanic","other",NA))

anes$nationecon=anes$V161140X

anes$nationecon=recode(anes$nationecon, '1=0;2=1/4;3=2/4;4=3/4;5=1;-1=NA')

anes$futureworse1=anes$V161111
anes$futureworse1=recode(anes$futureworse1,'1=0;2=1/4;3=2/4;4=3/4;5=1;-9=NA;-8=NA')


anes$financeworry1=anes$V162165
anes$financeworry1=recode(anes$financeworry1,'5=0;4=1/4;3=2/4;2=3/4;1=1;-9=NA;-8=NA;-7=NA;-6=NA')


anes$losejob1=anes$V161297
anes$losejob1=recode(anes$losejob1,'1=0;2=1/4;3=2/4;4=3/4;5=1;-9=NA;-1=NA')


anes$pastworse1=anes$V161110
anes$pastworse1=recode(anes$pastworse1,'1=0;2=1/4;3=2/4;4=3/4;5=1;-9=NA;-8=NA')


anes$eduONE=anes$edu1
anes$eduONE=recode(anes$eduONE,'1=0;2=1/4;3=2/4;4=3/4;5=1')

sanes=svydesign(id=~V160202, weights=~V160102,strata = ~V160201,nest=TRUE,survey.lonely.psu = "adjust",data=anes)


#################################

# Govt reduce income differences 1-5
govtincomePASTRR=svyglm(govtreducediffincome~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtincomeFUTURERR=svyglm(govtreducediffincome~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtincomeLOSERR=svyglm(govtreducediffincome~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtincomeFINANCERR=svyglm(govtreducediffincome~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtincomeALLRR=svyglm(govtreducediffincome~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


##############

# Govt provide jobs and income 1-7

govtjobPASTRR=svyglm(govtprovidejobs~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtjobFUTURERR=svyglm(govtprovidejobs~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtjobLOSERR=svyglm(govtprovidejobs~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtjobFINANCERR=svyglm(govtprovidejobs~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

govtjobALLRR=svyglm(govtprovidejobs~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


##############

#How much opportunity to get ahead? 1-5

oppPASTRR=svyglm(oppgetahead~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

oppFUTURERR=svyglm(oppgetahead~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

oppLOSERR=svyglm(oppgetahead~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

oppFINANCERR=svyglm(oppgetahead~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

oppALLRR=svyglm(oppgetahead~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


############
#BigBiz 0-100

bigPASTRR=svyglm(bigbizfeel~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

bigFUTURERR=svyglm(bigbizfeel~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

bigLOSERR=svyglm(bigbizfeel~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

bigFINANCERR=svyglm(bigbizfeel~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

bigALLRR=svyglm(bigbizfeel~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


#############
#Richppl 0-100
richPASTRR=svyglm(richpplfeel~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

richFUTURERR=svyglm(richpplfeel~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

richLOSERR=svyglm(richpplfeel~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

richFINANCERR=svyglm(richpplfeel~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

richALLRR=svyglm(richpplfeel~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


##########
# Poorppl 0-100

poorPASTRR=svyglm(poorpplfeel~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

poorFUTURERR=svyglm(poorpplfeel~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

poorLOSERR=svyglm(poorpplfeel~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

poorFINANCERR=svyglm(poorpplfeel~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)

poorALLRR=svyglm(poorpplfeel~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent+race,design=sanes)


###############
# Racial DVs
# Uses white respondents only
###############
whitesanes=subset(sanes,race=="white")
#####
# Racial Resentment 0-1 #
#####
racePASTRR=svyglm(racialresent~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion,design=whitesanes)

raceFUTURERR=svyglm(racialresent~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion,design=whitesanes)

raceLOSERR=svyglm(racialresent~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion,design=whitesanes)

raceFINANCERR=svyglm(racialresent~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion,design=whitesanes)

raceALLRR=svyglm(racialresent~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion,design=whitesanes)


########
# Whites can't find jobs because employers hire minorities instead 1-5 #
#######

minPASTRR=svyglm(minortakejobs~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

minFUTURERR=svyglm(minortakejobs~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

minLOSERR=svyglm(minortakejobs~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

minFINANCERR=svyglm(minortakejobs~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

minALLRR=svyglm(minortakejobs~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)


#######
# Immigrants take jobs 1-4 #
#######

immPASTRR=svyglm(immtakejobs~pastworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

immFUTURERR=svyglm(immtakejobs~futureworse1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

immLOSERR=svyglm(immtakejobs~losejob1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

immFINANCERR=svyglm(immtakejobs~financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

immALLRR=svyglm(immtakejobs~pastworse1+futureworse1+losejob1+financeworry1+income10k+eduONE+nationecon+age+union+ideology+party+female+religion+racialresent,design=whitesanes)

```

```{r govt_reduce_income_diff, message=FALSE, results='asis'}
require(stargazer)
stargazer(govtincomePASTRR,govtincomeFUTURERR,govtincomeLOSERR,govtincomeFINANCERR,govtincomeALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="Government Should Reduce Income Differences (Disagree Strongly to Agree Strongly; 5 Categories)",
          dep.var.labels = "Government Should Reduce Income Differences"
          )

```

```{r govt_provide_job_income, message=F, results='asis'}

stargazer(govtjobPASTRR,govtjobFUTURERR,govtjobLOSERR,govtjobFINANCERR,govtjobALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="Government Should Provide Jobs and Income (Should let each person get ahead on own to Should provide jobs and income; 7 categories)",
          dep.var.labels = "Government Should Provide Jobs and Income"
          )

```

```{r opportunity, message=F,results='asis'}
stargazer(oppPASTRR,oppFUTURERR,oppLOSERR,oppFINANCERR,oppALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="How much opportunity to get ahead? (A great deal to None; 5 categories)",
          dep.var.labels = "How much opportunity to get ahead?"
          )

```

```{r bigbiz, message=F,results='asis'}
stargazer(bigPASTRR,bigFUTURERR,bigLOSERR,bigFINANCERR,bigALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="Big Business Feeling Thermometer (0-100)",
          dep.var.labels = "Big Business Feeling Thermometer"
          )

```

```{r richppl,message=F,results='asis'}
stargazer(richPASTRR,richFUTURERR,richLOSERR,richFINANCERR,richALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="Rich People Feeling Thermometer (0-100)",
          dep.var.labels = "Rich People Feeling Thermometer"
          )

```

```{r poorppl,message=F,results='asis'}
stargazer(poorPASTRR,poorFUTURERR,poorLOSERR,poorFINANCERR,poorALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union", "Ideology","Party ID", "Female","Religion","Racial Resentment","Black","Asian","Native American","Hispanic","Other"),
          title="Poor People Feeling Thermometer (0-100)",
          dep.var.labels = "Poor People Feeling Thermometer"
          )

```

```{r racialresent,message=F,results='asis'}
stargazer(racePASTRR,raceFUTURERR,raceLOSERR,raceFINANCERR,raceALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union","Ideology","Party ID","Female","Religion"),
          title="Racial Resentment (0-1), white respondents only",
          dep.var.labels = "Racial Resentment"
          )

```

```{r minor_take_jobs, message=F,results='asis'}
stargazer(minPASTRR,minFUTURERR,minLOSERR,minFINANCERR,minALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union","Ideology","Party ID","Female","Religion", "Racial Resentment"),
          title="How likely is it that many whites are unable to find a job because employers are hiring minorities instead? (Not at all likely to Extremely likely; 5 categories), white respondents only",
          dep.var.labels = "Minorities hired instead of whites"
          )

```

```{r imm_take_jobs, message=F,results='asis'}
stargazer(immPASTRR,immFUTURERR,immLOSERR,immFINANCERR,immALLRR,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser"),
          covariate.labels=c("Past Worse","Future Worse","Job Insecure","Financial Anxiety","Income
                             10k","Education","National Economy","Age","Union","Ideology","Party ID","Female","Religion", "Racial Resentment"),
          title="How likely is it that recent immigration levels will take jobs away from people already here? (Not at all likely to Extremely likely; 4 categories), white respondents only",
          dep.var.labels = "Immigrants take jobs from people already here"
          )

```

```{r matching,message=F,results='hide'}
setwd("~/Desktop/Political Behavior RandR")
require(data.table)

anesM=fread("USE_FOR_MATCHING.csv", stringsAsFactors = F,data.table = F)


anesM$raceNUM=ifelse(anesM$V161310X==-9,NA,anesM$V161310X)


library(MatchIt)
library(dplyr)


#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean_incomediff=mean(govtreducediffincome,na.rm = T),
#            std_dev=sd(govtreducediffincome, na.rm=T),
#            std_error=std_dev/n_cases)
#
#REDUCEDIFFTtest=t.test(anesM$govtreducediffincome~anesM$financedummy)
#REDUCEDIFFTtest 
#
#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(govtprovidejobs,na.rm = T),
#            std_dev=sd(govtprovidejobs, na.rm=T),
#            std_error=std_dev/n_cases)
#
#PROVIDEJOBSTtest=t.test(anesM$govtprovidejobs~anesM$financedummy)
#PROVIDEJOBSTtest  
#
#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(oppgetahead,na.rm = T),
#            std_dev=sd(oppgetahead, na.rm=T),
#            std_error=std_dev/n_cases)
#
#OPPTtest=t.test(anesM$oppgetahead~anesM$financedummy)
#OPPTtest 
#
#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(bigbizfeel,na.rm = T),
#            std_dev=sd(bigbizfeel, na.rm=T),
#            std_error=std_dev/n_cases)
#
#BIGBIZTtest=t.test(anesM$bigbizfeel~anesM$financedummy)
#BIGBIZTtest
#
#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(richpplfeel,na.rm = T),
#            std_dev=sd(richpplfeel, na.rm=T),
#            std_error=std_dev/n_cases)
#
#RICHTtest=t.test(anesM$richpplfeel~anesM$financedummy)
#RICHTtest
#
#anesM %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(poorpplfeel,na.rm = T),
#            std_dev=sd(poorpplfeel, na.rm=T),
#            std_error=std_dev/n_cases)
#
#POORTtest=t.test(anesM$poorpplfeel~anesM$financedummy)
#POORTtest

anesWHITE=subset(anesM,race=="white")

#anesWHITE %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(racialresent,na.rm = T),
#            std_dev=sd(racialresent, na.rm=T),
#            std_error=std_dev/n_cases)
#
#RESENTTtest=t.test(anesWHITE$racialresent~anesWHITE$financedummy)
#RESENTTtest
#
#anesWHITE %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(minortakejobs,na.rm = T),
#            std_dev=sd(minortakejobs, na.rm=T),
#            std_error=std_dev/n_cases)
#
#MINORTAKETtest=t.test(anesWHITE$minortakejobs~anesWHITE$financedummy)
#MINORTAKETtest
#
#anesWHITE %>% 
#  group_by(financedummy) %>% 
#  summarise(n_cases=n(),
#            mean=mean(immtakejobs,na.rm = T),
#            std_dev=sd(immtakejobs, na.rm=T),
#            std_error=std_dev/n_cases)
#
#IMMTAKETtest=t.test(anesWHITE$immtakejobs~anesWHITE$financedummy)
#IMMTAKETtest

########

controlsR=c('raceNUM','nationecon','eduONE','coarseparty','racialresent','religion','female')
controlsW=c('nationecon','eduONE','coarseparty','racialresent','religion','female')

#anesM%>%
#  group_by(financedummy)%>%
#  select(one_of(controlsR))%>%
#  summarise_all(funs(mean(.,na.rm=T)))

#anesWHITE%>%
#  group_by(financedummy)%>%
#  select(one_of(controlsW))%>%
#  summarise_all(funs(mean(.,na.rm=T)))

#anes_na.omitR=anesM%>%
#  select(govtreducediffincome,govtprovidejobs,oppgetahead,bigbizfeel,
#         richpplfeel,poorpplfeel,financedummy,one_of(controlsR))%>%
#  na.omit()

anes_na.omitRINCOME=anesM%>%
  select(govtreducediffincome,financedummy,one_of(controlsR))%>%
  na.omit()

anes_na.omitRJOBS=anesM%>%
  select(govtprovidejobs,financedummy,one_of(controlsR))%>%
  na.omit()

anes_na.omitROPP=anesM%>%
  select(oppgetahead,financedummy,one_of(controlsR))%>%
  na.omit()

anes_na.omitRBIGBIZ=anesM%>%
  select(bigbizfeel,financedummy,one_of(controlsR))%>%
  na.omit()

anes_na.omitRRICH=anesM%>%
  select(richpplfeel,financedummy,one_of(controlsR))%>%
  na.omit()

anes_na.omitRPOOR=anesM%>%
  select(poorpplfeel,financedummy,one_of(controlsR))%>%
  na.omit()
#
Panes_na.omitRINCOME=anesM%>%
  select(govtreducediffincome,futuredummy,one_of(controlsR))%>%
  na.omit()

Panes_na.omitRJOBS=anesM%>%
  select(govtprovidejobs,futuredummy,one_of(controlsR))%>%
  na.omit()

Panes_na.omitROPP=anesM%>%
  select(oppgetahead,futuredummy,one_of(controlsR))%>%
  na.omit()

Panes_na.omitRBIGBIZ=anesM%>%
  select(bigbizfeel,futuredummy,one_of(controlsR))%>%
  na.omit()

Panes_na.omitRRICH=anesM%>%
  select(richpplfeel,futuredummy,one_of(controlsR))%>%
  na.omit()

Panes_na.omitRPOOR=anesM%>%
  select(poorpplfeel,futuredummy,one_of(controlsR))%>%
  na.omit()

#anes_na.omitW=anesWHITE%>%
#  select(racialresent,minortakejobs,immtakejobs,financedummy,one_of(controlsW))%>%
#  na.omit()
library("lmtest")
library("sandwich")
######################
# Govt should reduce income differences (1-5)

matchRINCOME=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                     method="cem", data=anes_na.omitRINCOME,
                     grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                   racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                   raceNUM=list(1,2,3,4,5,6)
                     ))

matchRINCOMEDATA=match.data(matchRINCOME)

matchgovtdiff=lm(govtreducediffincome~financedummy,data=matchRINCOMEDATA,weights=matchRINCOMEDATA$weights)
Rmatchgovtdiff=coeftest(matchgovtdiff,vcov.=vcovCL,cluster= ~subclass)
#

PmatchRINCOME=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                      method="cem", data=Panes_na.omitRINCOME,
                      grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                    racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                    raceNUM=list(1,2,3,4,5,6)
                      ))

PmatchRINCOMEDATA=match.data(PmatchRINCOME)


Pmatchgovtdiff=lm(govtreducediffincome~futuredummy,data=PmatchRINCOMEDATA,weights=PmatchRINCOMEDATA$weights)
RPmatchgovtdiff=coeftest(Pmatchgovtdiff,vcov.=vcovCL,cluster= ~subclass)

##########

#Govt should provide jobs and income (1-7)

matchRJOBS=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                   method="cem", data=anes_na.omitRJOBS,
                   grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                 racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                 raceNUM=list(1,2,3,4,5,6)
                   ))

matchRJOBDATA=match.data(matchRJOBS)

matchgovtjobs=lm(govtprovidejobs~financedummy,data=matchRJOBDATA,weights=matchRJOBDATA$weights)
Rmatchgovtjobs=coeftest(matchgovtjobs,vcov.=vcovCL,cluster= ~subclass)

#
PmatchRJOBS=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                    method="cem", data=Panes_na.omitRJOBS,
                    grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                  racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                  raceNUM=list(1,2,3,4,5,6)
                    ))

PmatchRJOBDATA=match.data(PmatchRJOBS)

Pmatchgovtjobs=lm(govtprovidejobs~futuredummy,data=PmatchRJOBDATA,weights=PmatchRJOBDATA$weights)
RPmatchgovtjobs=coeftest(Pmatchgovtjobs,vcov.=vcovCL,cluster= ~subclass)
########

#How much opportunity to get ahead? (1-5)
matchROPP=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                  method="cem", data=anes_na.omitROPP,
                  grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                raceNUM=list(1,2,3,4,5,6)
                  ))

matchROPPDATA=match.data(matchROPP)


matchopp=lm(oppgetahead~financedummy,data=matchROPPDATA,weights=matchROPPDATA$weights)
Rmatchopp=coeftest(matchopp,vcov.=vcovCL,cluster= ~subclass)

#
PmatchROPP=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                   method="cem", data=Panes_na.omitROPP,
                   grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                 racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                 raceNUM=list(1,2,3,4,5,6)
                   ))

PmatchROPPDATA=match.data(PmatchROPP)


Pmatchopp=lm(oppgetahead~futuredummy,data=PmatchROPPDATA,weights=PmatchROPPDATA$weights)
RPmatchopp=coeftest(Pmatchopp,vcov.=vcovCL,cluster= ~subclass)
###########

#Bigbiz feel

matchRBIGBIZ=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                     method="cem", data=anes_na.omitRBIGBIZ,
                     grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                   racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                   raceNUM=list(1,2,3,4,5,6)
                     ))

matchRBIGDATA=match.data(matchRBIGBIZ)


matchbigbiz=lm(bigbizfeel~financedummy,data=matchRBIGDATA,weights=matchRBIGDATA$weights)
Rmatchbigbiz=coeftest(matchbigbiz,vcov.=vcovCL,cluster= ~subclass)

#

PmatchRBIGBIZ=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                      method="cem", data=Panes_na.omitRBIGBIZ,
                      grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                    racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                    raceNUM=list(1,2,3,4,5,6)
                      ))

PmatchRBIGDATA=match.data(PmatchRBIGBIZ)


Pmatchbigbiz=lm(bigbizfeel~futuredummy,data=PmatchRBIGDATA,weights=PmatchRBIGDATA$weights)
RPmatchbigbiz=coeftest(Pmatchbigbiz,vcov.=vcovCL,cluster= ~subclass)

#########
#Rich ppl feel

matchRRICH=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                   method="cem", data=anes_na.omitRRICH,
                   grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                 racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                 raceNUM=list(1,2,3,4,5,6)
                   ))

matchRRICHDATA=match.data(matchRRICH)


matchrich=lm(richpplfeel~financedummy,data=matchRRICHDATA,weights=matchRRICHDATA$weights)
Rmatchrich=coeftest(matchrich,vcov.=vcovCL,cluster= ~subclass)

#
PmatchRRICH=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                    method="cem", data=Panes_na.omitRRICH,
                    grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                  racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                  raceNUM=list(1,2,3,4,5,6)
                    ))

PmatchRRICHDATA=match.data(PmatchRRICH)


Pmatchrich=lm(richpplfeel~futuredummy,data=PmatchRRICHDATA,weights=PmatchRRICHDATA$weights)
RPmatchrich=coeftest(Pmatchrich,vcov.=vcovCL,cluster= ~subclass)



#############

#Poor ppl feel
matchRPOOR=matchit(financedummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                   method="cem", data=anes_na.omitRPOOR,
                   grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                 racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                 raceNUM=list(1,2,3,4,5,6)
                   ))

matchRPOORDATA=match.data(matchRPOOR)


matchpoor=lm(poorpplfeel~financedummy,data=matchRPOORDATA,weights=matchRPOORDATA$weights)
Rmatchpoor=coeftest(matchpoor,vcov.=vcovCL,cluster= ~subclass)

#
PmatchRPOOR=matchit(futuredummy~nationecon+eduONE+racialresent+religion+female+coarseparty+raceNUM, 
                    method="cem", data=Panes_na.omitRPOOR,
                    grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                  racialresent=list(0:0.4375,0.5:0.5625,0.625:1),
                                  raceNUM=list(1,2,3,4,5,6)
                    ))

PmatchRPOORDATA=match.data(PmatchRPOOR)


Pmatchpoor=lm(poorpplfeel~futuredummy,data=PmatchRPOORDATA,weights=PmatchRPOORDATA$weights)
RPmatchpoor=coeftest(Pmatchpoor,vcov.=vcovCL,cluster= ~subclass)


#########  

anes_na.omitWRESENT=anesWHITE%>%
  select(racialresent,financedummy,one_of(controlsW))%>%
  na.omit()

anes_na.omitWMINOR=anesWHITE%>%
  select(minortakejobs,financedummy,one_of(controlsW))%>%
  na.omit()

anes_na.omitWIMM=anesWHITE%>%
  select(immtakejobs,financedummy,one_of(controlsW))%>%
  na.omit()
#
Panes_na.omitWRESENT=anesWHITE%>%
  select(racialresent,futuredummy,one_of(controlsW))%>%
  na.omit()

Panes_na.omitWMINOR=anesWHITE%>%
  select(minortakejobs,futuredummy,one_of(controlsW))%>%
  na.omit()

Panes_na.omitWIMM=anesWHITE%>%
  select(immtakejobs,futuredummy,one_of(controlsW))%>%
  na.omit()

##########
#Racial resent, whites only (0-1)

matchWRESENT=matchit(financedummy~nationecon+eduONE+religion+female+coarseparty, 
                     method="cem", data=anes_na.omitWRESENT,
                     grouping=list(nationecon=list(0:0.25,0.5,0.75:1)
                     ))

matchWRESENTDATA=match.data(matchWRESENT)


matchresent=lm(racialresent~financedummy,data=matchWRESENTDATA,weights=matchWRESENTDATA$weights)
Rmatchresent=coeftest(matchresent,vcov.=vcovCL,cluster= ~subclass)

#
PmatchWRESENT=matchit(futuredummy~nationecon+eduONE+religion+female+coarseparty, 
                      method="cem", data=Panes_na.omitWRESENT,
                      grouping=list(nationecon=list(0:0.25,0.5,0.75:1)
                      ))

PmatchWRESENTDATA=match.data(PmatchWRESENT)


Pmatchresent=lm(racialresent~futuredummy,data=PmatchWRESENTDATA,weights=PmatchWRESENTDATA$weights)
RPmatchresent=coeftest(Pmatchresent,vcov.=vcovCL,cluster= ~subclass)



#########

#Minorities take jobs, whites only, 1-5

matchWMINOR=matchit(financedummy~nationecon+eduONE+religion+female+coarseparty+racialresent, 
                    method="cem", data=anes_na.omitWMINOR,
                    grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                  racialresent=list(0:0.4375,0.5:0.5625,0.625:1)
                    ))

matchWMINORDATA=match.data(matchWMINOR)


matchminor=lm(minortakejobs~financedummy,data=matchWMINORDATA,weights=matchWMINORDATA$weights)
Rmatchminor=coeftest(matchminor,vcov.=vcovCL,cluster= ~subclass)

#
PmatchWMINOR=matchit(futuredummy~nationecon+eduONE+religion+female+coarseparty+racialresent, 
                     method="cem", data=Panes_na.omitWMINOR,
                     grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                   racialresent=list(0:0.4375,0.5:0.5625,0.625:1)
                     ))

PmatchWMINORDATA=match.data(PmatchWMINOR)


Pmatchminor=lm(minortakejobs~futuredummy,data=PmatchWMINORDATA,weights=PmatchWMINORDATA$weights)
RPmatchminor=coeftest(Pmatchminor,vcov.=vcovCL,cluster= ~subclass)


############
#Immigrants take jobs, whites only, 1-4

matchWIMM=matchit(financedummy~nationecon+eduONE+religion+female+coarseparty+racialresent, 
                  method="cem", data=anes_na.omitWIMM,
                  grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                racialresent=list(0:0.4375,0.5:0.5625,0.625:1)
                  ))

matchWIMMDATA=match.data(matchWIMM)


matchimm=lm(immtakejobs~financedummy,data=matchWIMMDATA,weights=matchWIMMDATA$weights)
Rmatchimm=coeftest(matchimm,vcov.=vcovCL,cluster= ~subclass)

#
PmatchWIMM=matchit(futuredummy~nationecon+eduONE+religion+female+coarseparty+racialresent, 
                   method="cem", data=Panes_na.omitWIMM,
                   grouping=list(nationecon=list(0:0.25,0.5,0.75:1),
                                 racialresent=list(0:0.4375,0.5:0.5625,0.625:1)
                   ))

PmatchWIMMDATA=match.data(PmatchWIMM)


Pmatchimm=lm(immtakejobs~futuredummy,data=PmatchWIMMDATA,weights=PmatchWIMMDATA$weights)
RPmatchimm=coeftest(Pmatchimm,vcov.=vcovCL,cluster= ~subclass)


```

```{r AFFmatchredistribution, message=F,results='asis'}
stargazer(Rmatchgovtdiff,Rmatchgovtjobs,Rmatchopp,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Affective Econ. Insecurity Treatment",
          dep.var.labels=c('\\shortstack{Govt should\\\\ reduce income\\\\ differences\\\\(Disagree strongly\\\\ to Agree strongly;\\\\ 5 categories)}','\\shortstack{Govt should\\\\ provide jobs\\\\ and income\\\\(Get ahead\\\\on own to\\\\Provide jobs\\\\and income;\\\\7 categories)}','\\shortstack{How much\\\\ opportunity?\\\\(A great\\\\deal to\\\\None; 5\\\\categories)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","706","616","710"),
                         c("n, control","748","664","752")),
          title="CEM: Average Treatment Effect of Affective Econ. Insecurity on Redistributive Attitudes"
)
```

```{r Cmatchredistribution, message=F,results='asis'}
stargazer(RPmatchgovtdiff,RPmatchgovtjobs,RPmatchopp,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Future Worse Treatment",
          dep.var.labels=c('\\shortstack{Govt should\\\\ reduce income\\\\ differences\\\\(Disagree strongly\\\\ to Agree strongly;\\\\ 5 categories)}','\\shortstack{Govt should\\\\ provide jobs\\\\ and income\\\\(Get ahead\\\\on own to\\\\Provide jobs\\\\and income;\\\\7 categories)}','\\shortstack{How much\\\\ opportunity?\\\\(A great\\\\deal to\\\\None; 5\\\\categories)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","277","243","277"),
                         c("n, control","572","501","576")),
          title="CEM: Average Treatment Effect of Cognitive Econ. Insecurity on Redistributive Attitudes"
)
```


```{r AFFmatch_class, message=F,results='asis'}
stargazer(Rmatchbigbiz,Rmatchrich,Rmatchpoor,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Affective Econ. Insecurity Treatment",
          dep.var.labels=c('\\shortstack{Big\\\\ Business\\\\ (0-100)}','\\shortstack{Rich\\\\ people\\\\ (0-100)}','\\shortstack{Poor\\\\ People\\\\(0-100)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","705","702","700"),
                         c("n, control","744","744","743")),
          title="CEM: Average Treatment Effect of Affective Econ. Insecurity on Class Attitudes"
)
```

```{r Cmatch_class, message=F,results='asis'}
stargazer(RPmatchbigbiz,RPmatchrich,RPmatchpoor,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Future Worse Treatment",
          dep.var.labels=c('\\shortstack{Big\\\\ Business\\\\ (0-100)}','\\shortstack{Rich\\\\ people\\\\ (0-100)}','\\shortstack{Poor\\\\ People\\\\(0-100)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","273","275","268"),
                         c("n, control","564","569","555")),
          title="CEM: Average Treatment Effect of Cognitive Econ. Insecurity on Class Attitudes"
)
```


```{r AFFmatch_race, message=F,results='asis'}
stargazer(Rmatchresent,Rmatchminor,Rmatchimm,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Affective Econ. Insecurity Treatment",
          dep.var.labels=c('\\shortstack{Racial\\\\ Resentment\\\\ (0-1)}','\\shortstack{Minorities hired\\\\instead of \\\\whites\\\\ (Not at all\\\\likely to\\\\Extremely likely;\\\\4 categories)}','\\shortstack{Immigrants\\\\ take jobs from\\\\people already\\\\here (Not at all\\\\likely to\\\\Extremely likely;\\\\4 categories)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","1,230","624","637"),
                         c("n, control","1,204","668","682")),
          title="CEM: Average Treatment Effect of Affective Econ. Insecurity on Racial Attitudes; white respondents only"
)
```

```{r Cmatch_race, message=F,results='asis'}
stargazer(RPmatchresent,RPmatchminor,RPmatchimm,
          type="latex",
          header=F,
          single.row=F,
          no.space=F,
          style="apsr",
          omit.stat=c("f","ser","rsq","adj.rsq"),
          covariate.labels="Future Worse Treatment",
          dep.var.labels=c('\\shortstack{Racial\\\\ Resentment\\\\ (0-1)}','\\shortstack{Minorities hired\\\\instead of \\\\whites\\\\ (Not at all\\\\likely to\\\\Extremely likely;\\\\4 categories)}','\\shortstack{Immigrants\\\\ take jobs from\\\\people already\\\\here (Not at all\\\\likely to\\\\Extremely likely;\\\\4 categories)}'),
          omit="Constant",
          add.lines=list(c("n, treatment","385","249","254"),
                         c("n, control","1,816","524","548")),
          title="CEM: Average Treatment Effect of Cognitive Econ. Insecurity on Racial Attitudes; white respondents only"
)
```

